package org.newcih.activiti.controller;

import org.activiti.engine.FormService;
import org.activiti.engine.form.StartFormData;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("chapter6")
public class StartController {

    @Autowired
    private FormService formService;

    @RequestMapping("getform/start/{processDefinitionId}")
    public ModelAndView readStartForm(@PathVariable("processDefinitionId") String processDefinitionId) {
        String viewName = "chapter6/start-process-form";
        ModelAndView modelAndView = new ModelAndView(viewName);
        StartFormData startFormData = formService.getStartFormData(processDefinitionId);

        modelAndView.addObject("startFormData", startFormData);
        modelAndView.addObject("processDefinitionId", processDefinitionId);

        return modelAndView;
    }

}
